home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_10 / plauger / complex < prev   
Text File  |  1995-08-06  |  6KB  |  171 lines

  1. ------------- Listing 1: The Header <complex> ---------
  2.  
  3. #define __STD_COMPLEX
  4.                 // TEMPLATE CLASS complex
  5. template<class T>
  6.         class complex {
  7. public:
  8.         complex(T re = 0, T im = 0);
  9.         template<class U>
  10.                 complex(const complex<U>& x);
  11.         T real() const;
  12.         T imag() const;
  13.         template<class U>
  14.                 complex<T>& operator=(const complex<U>& rhs);
  15.         template<class U>
  16.                 complex<T>& operator+=(const complex<U>& rhs);
  17.         template<class U>
  18.                 complex<T>& operator-=(const complex<U>& rhs);
  19.         template<class U>
  20.                 complex<T>& operator*=(const complex<U>& rhs);
  21.         template<class U>
  22.                 complex<T>& operator/=(const complex<U>& rhs);
  23.         };
  24.                 // CLASS complex<float>
  25. class complex<float> {
  26. public:
  27.         complex(float re = 0, float im = 0);
  28.         explicit complex(const complex<double>& rhs);
  29.         explicit complex(const complex<long double>& rhs);
  30.         template<class U>
  31.                 complex<float>& operator=(const complex<U>& rhs);
  32.         template<class U>
  33.                 complex<float>& operator+=(const complex<U>& rhs);
  34.         template<class U>
  35.                 complex<float>& operator-=(const complex<U>& rhs);
  36.         template<class U>
  37.                 complex<float>& operator*=(const complex<U>& rhs);
  38.         template<class U>
  39.                 complex<float>& operator/=(const complex<U>& rhs);
  40.         };
  41.                 // CLASS complex<double>
  42. class complex<double> {
  43. public:
  44.         complex(double re = 0, double im = 0);
  45.         complex(const complex<float>& rhs);
  46.         explicit complex(const complex<long double>& rhs);
  47.         template<class U>
  48.                 complex<double>& operator=(const complex<U>& rhs);
  49.         template<class U>
  50.                 complex<double>& operator+=(const complex<U>& rhs);
  51.         template<class U>
  52.                 complex<double>& operator-=(const complex<U>& rhs);
  53.         template<class U>
  54.                 complex<double>& operator*=(const complex<U>& rhs);
  55.         template<class U>
  56.                 complex<double>& operator/=(const complex<U>& rhs);
  57.         };
  58.                 // CLASS complex<long double>
  59. class complex<long double> {
  60. public:
  61.         complex(long double re = 0, long double im = 0);
  62.         complex(const complex<float>& rhs);
  63.         complex(const complex<double>& rhs);
  64.         template<class U>
  65.                 complex<long double>& operator=(
  66.                         const complex<U>& rhs);
  67.         template<class U>
  68.                 complex<long double>& operator+=(
  69.                         const complex<U>& rhs);
  70.         template<class U>
  71.                 complex<long double>& operator-=(
  72.                         const complex<U>& rhs);
  73.         template<class U>
  74.                 complex<long double>& operator*=(
  75.                         const complex<U>& rhs);
  76.         template<class U>
  77.                 complex<long double>& operator/=(
  78.                         const complex<U>& rhs);
  79.         };
  80.                 // TEMPLATE FUNCTIONS FOR complex
  81. template<class T>
  82.         complex<T> operator+(const complex<T>& lhs,
  83.                 const complex<T>& rhs);
  84. template<class T>
  85.         complex<T> operator+(const complex<T>& lhs, T rhs);
  86. template<class T>
  87.         complex<T> operator+(T lhs, const complex<T>& rhs);
  88. template<class T>
  89.         complex<T> operator-(const complex<T>& lhs,
  90.                 const complex<T>& rhs);
  91. template<class T>
  92.         complex<T> operator-(const complex<T>& lhs, T rhs);
  93. template<class T>
  94.         complex<T> operator-(T lhs, const complex<T>& rhs);
  95. template<class T>
  96.         complex<T> operator*(const complex<T>& lhs,
  97.                 const complex<T>& rhs);
  98. template<class T>
  99.         complex<T> operator*(const complex<T>& lhs, T rhs);
  100. template<class T>
  101.         complex<T> operator*(T lhs, const complex<T>& rhs);
  102. template<class T>
  103.         complex<T> operator/(const complex<T>& lhs,
  104.                 const complex<T>& rhs);
  105. template<class T>
  106.         complex<T> operator/(const complex<T>& lhs, T rhs);
  107. template<class T>
  108.         complex<T> operator/(T lhs, const complex<T>& rhs);
  109. template<class T>
  110.         complex<T> operator+(const complex<T>& lhs);
  111. template<class T>
  112.         complex<T> operator-(const complex<T>& lhs);
  113. template<class T>
  114.         bool operator==(const complex<T>& lhs,
  115.                 const complex<T>& rhs);
  116. template<class T>
  117.         bool operator==(const complex<T>& lhs, T rhs);
  118. template<class T>
  119.         bool operator==(T lhs, const complex<T>& rhs);
  120. template<class T>
  121.         bool operator!=(const complex<T>& lhs,
  122.                 const complex<T>& rhs);
  123. template<class T>
  124.         bool operator!=(const complex<T>& lhs, T rhs);
  125. template<class T>
  126.         bool operator!=(T lhs, const complex<T>& rhs);
  127. template<class T>
  128.         istream& operator>>(istream& is, complex<T>& x);
  129. template<class T>
  130.         ostream& operator<<(ostream& os, const complex<T>& x);
  131. template<class T>
  132.         T real(const complex<T>& x);
  133. template<class T>
  134.         T imag(const complex<T>& x);
  135. template<class T>
  136.         T abs(const complex<T>& x);
  137. template<class T>
  138.         T arg(const complex<T>& x);
  139. template<class T>
  140.         T norm(const complex<T>& x);
  141. template<class T>
  142.         complex<T> conjg(const complex<T>& x);
  143. template<class T>
  144.         complex<T> polar(T rho, T theta);
  145. template<class T>
  146.         complex<T> cos(const complex<T>& x);
  147. template<class T>
  148.         complex<T> cosh(const complex<T>& x);
  149. template<class T>
  150.         complex<T> exp(const complex<T>& x);
  151. template<class T>
  152.         complex<T> log(const complex<T>& x);
  153. template<class T>
  154.         complex<T> log10(const complex<T>& x);
  155. template<class T>
  156.         complex<T> pow(const complex<T>& x, int y);
  157. template<class T>
  158.         complex<T> pow(const complex<T>& x, T y);
  159. template<class T>
  160.         complex<T> pow(const complex<T>& x,
  161.                 const complex<T>& y);
  162. template<class T>
  163.         complex<T> pow(T x, const complex<T>& y);
  164. template<class T>
  165.         complex<T> sin(const complex<T>& x);
  166. template<class T>
  167.         complex<T> sinh(const complex<T>& x);
  168. template<class T>
  169.         complex<T> sqrt(const complex<T>& x);
  170.  
  171.